<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随机猜数字</title>
</head>

<body>
    <script>
        var x = parseInt(Math.random() * 10);
            var y;
 
        for( var i=0;i<Infinity;i++){
        y= Number(prompt('请输入你猜测的数字'));
            if (x > y) {
                alert('你猜小了')
            }
            else if (x < y) {
                alert('你猜大了')
            } else {
                alert('你猜对了');
                break;
            }
        }  
    </script>
</body>

</html>